package com.tcl.logoidentify.commons;

import java.io.File;
import java.io.IOException;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.base.Charsets;
import com.google.common.io.Files;
import com.google.common.io.LineProcessor;

public class ChannelsInfo {
	private static final Logger logger = LoggerFactory.getLogger(ChannelsInfo.class);
	private static final Map<Integer, String[]> map = new ConcurrentHashMap<Integer, String[]>();
	static {
		try {
			String path = Thread.currentThread().getContextClassLoader().getResource("chs.conf").getPath();
			Files.readLines(new File(path), Charsets.UTF_8, new LineProcessor<Map<Integer, String[]>>() {
				@Override
				public Map<Integer, String[]> getResult() {
					return map;
				}

				@Override
				public boolean processLine(String ln) throws IOException {
					if (Validate.notEmpty(ln)) {
						String[] fields = ln.split(",");
						map.put(Integer.valueOf(fields[0]), new String[] { fields[0], fields[1], fields[2] });
					}
					return true;
				}

			});
		} catch (IOException e) {
			logger.error("加载频道信息出错", e);
		}

	}

	public static String[] getChannelInfo(Integer ch_id) {
		String[] info = map.get(ch_id);
		if (info == null) {
			info = new String[] { "", "", "" };
		}
		return info;
	}

}
